//@author A0087294-reused
#ifndef __OutputLevelRunTimeSwitch_h__
#define __OutputLevelRunTimeSwitch_h__

#include "LoggerLevel.h"

namespace logging {

    /*! \brief Treatment of logging levels can be switched at runtime
     */
    template < typename Base >
    class OutputLevelRunTimeSwitch  : public Base {
            ::logging::Level _level;
            ::logging::Level _current;
        public:
            OutputLevelRunTimeSwitch() {
                _level.l = ::logging::Level::normal | ::logging::Level::error;
                _current.l = ::logging::Level::normal;
            }

            /*! \brief Output is only allowed if the current %level is switched
             *         on in the general %level.
             */
            bool allowed() {
                return !!(_level&_current);
            }

            /*! \brief Matches only on correct type and set the
             *         current %level for the output.
             */
            OutputLevelRunTimeSwitch& operator<<(const ::logging::Level::levels& l) {
                _current = l;
                return *this;
            }

            /*! \brief The operator matches on every type, and delegates further
             *         work to the base class if the output is currently
             *         allowed.
             */
            template< typename T>
            OutputLevelRunTimeSwitch& operator<<(T t) {
                if ( allowed() )
                    Base::operator<<(t);
                return *this;
            }
    };

} /* logging */

#endif
